﻿@using Library
@model Ecommerce.Models.ProductImageViewModel

@using (Ajax.BeginForm("EditProductImage", "Admin", new AjaxOptions
{
    AllowCache = false,
    HttpMethod = "POST",
    UpdateTargetId = "formctnr",
    InsertionMode = InsertionMode.Replace,
    OnSuccess = "onSuccess"
}, new { @id = "product-image-form", @class = "form-horizontal", @enctype = "multipart/form-data", @data_productid = Model.ProductId.ToString(), @data_imgsrc = (ViewBag.IsEdit ? Model.Src : "") }))
{
    <div class="modal-body">
        @Html.AntiForgeryToken()
        @Html.HiddenFor(m => m.ProductId)
        @Html.HiddenFor(m => m.Culture)
        @Html.HiddenFor(m => m.Src)
        @if (ViewBag.IsEdit)
        {
            <div class="form-group">
                <label class="col-sm-2 control-label">@NOWCulture.GetString("Image")</label>
                <div class="col-sm-10">
                    <div class="checkbox">
                        <a href="@(Model.Src)" target="_blank" title="@NOWCulture.GetString("View with original size")">@NOWCulture.GetString("Click here to show image")</a>
                    </div>
                </div>
            </div>
        }
        else
        {
            <div class="form-group">
                <label class="col-sm-2 control-label">@NOWCulture.GetString("Image")</label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.Image, new { @type = "file", @accept = "image/*", @class = "form-control", @title = NOWCulture.GetString("Browse an image to upload") })
                </div>
            </div>
        }
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                @Html.ValidationMessageFor(m => m.Image, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Image caption")</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(m => m.Caption, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.Caption, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">@NOWCulture.GetString("Image ALT text")</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(m => m.AltText, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.AltText, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <div class="checkbox">
                    <label>
                        @Html.CheckBoxFor(m => m.IsAvatar) @NOWCulture.GetString("Using for the avatar")
                    </label>
                </div>
            </div>
        </div>
        @Html.ValidationSummary(true, "", new { @class = "bg-danger" })
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">@NOWCulture.GetString("Close")</button>
        <input type="submit" class="btn btn-primary" value="@NOWCulture.GetString("Save")">
    </div>
    <script>$('input[type=file]').bootstrapFileInput();</script>
    @(HttpContext.Current.IsDebuggingEnabled ? Scripts.Render("~/bundles/admin-edit-product-image") : Scripts.RenderFormat(@"<script src=""{0}"" async defer></script>", "~/bundles/admin-edit-product-image"))
}
